//
//  BaseSettingTVC.m
//  KTLotteryTicket
//
//  Created by CoolKi on 16/3/8.
//  Copyright © 2016年 CoolKi. All rights reserved.
//

#import "BaseSettingTVC.h"


@interface BaseSettingTVC ()

@end

@implementation BaseSettingTVC

-(NSMutableArray *)groupArr{
    if (_groupArr == nil) {
        _groupArr = [NSMutableArray array];
    }
    return _groupArr;
}
-(instancetype)initWithStyle:(UITableViewStyle)style{
    return [super initWithStyle:UITableViewStyleGrouped];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.groupArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    KTGroupModel * model = self.groupArr[section];
    return model.cellModelArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    KTBaseCell * cell = [KTBaseCell cellWithTableView:tableView Style:UITableViewCellStyleDefault];
    
    KTGroupModel * model = self.groupArr[indexPath.section];
    KTBaseCellModel * cellModel = model.cellModelArr[indexPath.row];
    cell.cellModel = cellModel;
    
    return cell;
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    KTGroupModel * groupModel = self.groupArr[section];
    return groupModel.headerStr;
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    KTGroupModel * groupModel = self.groupArr[section];
    return groupModel.footerStr;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    KTGroupModel * groupModel = self.groupArr[indexPath.section];
    KTBaseCellModel * cellModel = groupModel.cellModelArr[indexPath.row];
    
    if ([cellModel isKindOfClass:[KTArrowCellModel class]]) {
        
        KTArrowCellModel * arrowCellModel = (KTArrowCellModel *)cellModel;
        
        if (arrowCellModel.destanceClss) {
            UIViewController * vc = [[arrowCellModel.destanceClss alloc]init];
            
            [self.navigationController pushViewController:vc animated:YES];
        }
    }else if ([cellModel isKindOfClass:[KTSwitchCellModel class]]){
        
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
